﻿using Assets.Scripts.DL.ComponentScripts;
using Assets.Scripts.DL.Consts;
using Assets.Scripts.DL.Enemy.CommonEnemy.States.Special;
using System.Collections;
using UnityEngine;

namespace Assets.Scripts.DL.Mgrs {
	public static class PoolTools {

		public static void MakeDmgNumber(Vector3 pos, int dmg) {
			var randomAngle = Random.Range(0, Mathf.PI * 2);
			var dir = new Vector2(Mathf.Cos(randomAngle), Mathf.Sin(randomAngle));
			var obj = ObjectPool.Instance.GetObject(ObjPoolStr.DmgNumber);
			obj.GetComponent<DamageNumber>().Init(dir, pos, dmg);
		}


		public static void MakeArrow(Vector2 pos, Vector2 v, string tag, int damage) {
			var arrow = ObjectPool.Instance.GetObject(ObjPoolStr.Arrow);
			arrow.GetComponent<Arrow>().Init(v, damage, tag);
			arrow.transform.position = pos;
		}

		public static IEnumerator MakeShadowCoroutin(int shadowCnt, Vector3 dir, Sprite sp, Transform trans, string animName = "Fade") {
			//yield return new WaitForSeconds(Time.deltaTime);//等当前物体的sprite改变
			//Timer timer = new();
			while (shadowCnt-- > 1) {
				var obj = ObjectPool.Instance.GetObject(ObjPoolStr.Shadow);
				var script = obj.GetComponent<Shadow>();
				script.Dir = dir;
				script.SetSprite(sp, animName);
				script.Tranform = trans;
				//Debug.Log(shadowCnt);
				yield return null;
			}
		}
		public static void MakeShadowSyn(Vector3 dir, Sprite sp, Transform trans, string animName = "Fade") {
			var obj = ObjectPool.Instance.GetObject(ObjPoolStr.Shadow);
			var script = obj.GetComponent<Shadow>();
			script.Dir = dir;
			script.SetSprite(sp, animName);
			script.Tranform = trans;
		}

		public static void MakeBloodBarEffect(Transform transform, RectTransform rectTransform, float before, float after) {
			var obj = ObjectPool.Instance.GetObject(ObjPoolStr.BloodEffect, transform);
			obj.transform.SetAsFirstSibling();
			//obj.GetComponent<RectTransform>().localPosition = GetComponent<RectTransform>().localPosition;//效果相同
			obj.GetComponent<RectTransform>().position = rectTransform.position;
			var script = obj.GetComponent<BloodBarEffect>();
			script.Init(before, after);
		}

		public static IEnumerator MakeDiciCoroutin(Vector3 centerPos, float disGap, int cnt, float timeGap) {
			var curXOff = new Vector3(disGap, 0, 0);
			while (cnt-- > 0) {
				var pos1 = centerPos + curXOff;
				var pos2 = centerPos - curXOff;
				ObjectPool.Instance.GetObject(ObjPoolStr.DiCi).GetComponent<DiCi>().Init(pos1);
				ObjectPool.Instance.GetObject(ObjPoolStr.DiCi).GetComponent<DiCi>().Init(pos2);
				curXOff.x += disGap;
				yield return new WaitForSeconds(timeGap);
			}
		}
	}
}
